package com.sl.ms.carriage.handler;

import com.sl.ms.base.api.common.AreaFeign;
import com.sl.ms.carriage.domain.constant.CarriageConstant;
import com.sl.ms.carriage.domain.dto.WaybillDTO;
import com.sl.ms.carriage.entity.CarriageEntity;
import com.sl.ms.carriage.service.CarriageService;
import com.sl.transport.common.util.ObjectUtil;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
@Order(200)
@Component
public class SameProvinceChainHandler extends AbstractCarriageChainHandler {
    @Resource
    private CarriageService carriageService;
    @Resource
    private AreaFeign areaFeign;
    @Override
    public CarriageEntity doHandler(WaybillDTO waybillDTO) {
        CarriageEntity carriageEntity=null;
        Long receiverProvinceId = areaFeign.get(waybillDTO.getReceiverCityId()).getParentId();
        Long senderProvinceId=areaFeign.get(waybillDTO.getSenderCityId()).getParentId();
        if(ObjectUtil.equals(receiverProvinceId,senderProvinceId)){
            carriageEntity=carriageService.findByTemplateType(CarriageConstant.SAME_PROVINCE);
        }
        return doNextHandler(waybillDTO,carriageEntity);
    }
}
